package com.wn.controller;

import com.wn.bean.Owner;
import com.wn.bean.OwnerQueryDto;
import com.wn.bean.Result;
import com.wn.service.IOwnerService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2024-07-01
 * @desc 蜗牛创想：www.woniuxy.com
 */
@RestController
@RequestMapping("/owner")
public class OwnerController {

    @Autowired
    private IOwnerService ownerService;

    @GetMapping("/list")
    public Result<List<Owner>> listOwner(OwnerQueryDto ownerQueryDto){
        System.out.println("ownerQueryDto = " + ownerQueryDto);
        List<Owner> owners = ownerService.listAllOwners(ownerQueryDto);
        return Result.ok(owners);
    }

    @PutMapping()
    public Result<String> updateOwnerById(@RequestBody Owner owner){
        boolean flag = ownerService.updateOwnerById(owner);
        return flag ? Result.ok() : Result.fail();
    }

    @DeleteMapping()
    public Result<String> delOwnerByIds(@RequestBody List<Integer> ids){
        System.out.println("ids = " + ids);
        boolean flag = ownerService.delOwnerByIds(ids);

        return flag ? Result.ok() : Result.fail();
    }

}
